package com.shuwen.gcdj.controller.basics;


import com.shuwen.gcdj.bean.DeleteReq;
import com.shuwen.gcdj.bean.DictResp;
import com.shuwen.gcdj.bean.SelectReq;
import com.shuwen.gcdj.bean.basicsEquitment.request.*;
import com.shuwen.gcdj.bean.basicsEquitment.response.*;
import com.shuwen.gcdj.common.annotation.JWTAuth;
import com.shuwen.gcdj.common.api.CommonPage;
import com.shuwen.gcdj.common.api.CommonResult;
import com.shuwen.gcdj.controller.AuthController;
import com.shuwen.gcdj.dto.account.InitUserDto;
import com.shuwen.gcdj.service.basics.EquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;


/***
 ** Created by psy
 ** Date:2023/5/9
 */
@Api(tags = "设备台账")
@Slf4j
@RestController
@RequestMapping
public class EquipmentController extends AuthController {

    @Autowired
    private EquipmentService equipmentService;

    @ApiOperation(value = "设备台账类型下拉选项")
    @PostMapping(value = "/basicsbelowcarparameter/getequipmenttypelist")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<EquipmentTypeResp>> getEquipmentTypeList(){
        return equipmentService.getEquipmentTypeList();
    }

    @ApiOperation(value = "获取设备台账标题")
    @GetMapping(value = "/basicsbelowcarparameter/getequipmenttitle/{code}")
    @ResponseBody
    @JWTAuth
    public CommonResult<EquipmentTitleResp> getEquipmentTitle(@PathVariable String code){
        return equipmentService.getEquipmentTitle(code);
    }

    @ApiOperation(value = "台账增加")
    @PostMapping(value = "/basicsbelowcarparameter/addequipmentmanagement")
    @ResponseBody
    @JWTAuth
    public CommonResult<StandingbookResp> equipmentAdd(@RequestBody @Valid StandingbookReq req, HttpServletRequest request){
        InitUserDto initUserDto = initUser(request);
        return equipmentService.equipmentAdd(req,initUserDto);
    }

    @ApiOperation(value = "台账修改")
    @PostMapping(value = "/basicsbelowcarparameter/editequipmentmanagement")
    @ResponseBody
    @JWTAuth
    public CommonResult<String> equipmentUpdate(@RequestBody @Valid EquipmentDetailsReq req, HttpServletRequest request){
        InitUserDto initUserDto = initUser(request);
        return equipmentService.equipmentUpdate(req,initUserDto);
    }

    @ApiOperation(value = "台账列表")
    @PostMapping(value = "/basicsbelowcarparameter/getequipmentmanagementpage")
    @ResponseBody
    @JWTAuth
    public CommonResult<CommonPage<EquipmentListResp>> equiomentList(@RequestBody ListPageReq req){
        return equipmentService.equipmentList(req);
    }

    @ApiOperation(value = "批量删除台账")
    @PostMapping(value = "/basicsbelowcarparameter/batchdeleteequipmentmanagement")
    @ResponseBody
    @JWTAuth
    public CommonResult<String> deleteEquipments(@RequestBody @Valid DeleteReq req, HttpServletRequest request){
        InitUserDto initUserDto = initUser(request);
        return equipmentService.deleteEquioments(req.getIds(),initUserDto);
    }

    @ApiOperation(value = "获取设备类型")
    @GetMapping(value = "/equipmentmanagement/getequipmenttypelist")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<DictResp>> getEquipmentType(){
        return equipmentService.getEquipmentType();
    }

    @ApiOperation(value = "上传文件夹id")
    @PostMapping(value = "/equipmentmanagement/getFolderId")
    @ResponseBody
    @JWTAuth
    public CommonResult<String> getFolderId(@RequestBody SelectReq req){
        return equipmentService.getFolderId(req.getId());
    }

    @ApiOperation(value = "获取设备区域")
    @GetMapping(value = "/equipmentmanagement/getequipmentarealocationlist")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<DictResp>> getEquipmentAreas(){
        return equipmentService.getEquipmentAreas();
    }

    @ApiOperation(value = "获取安装区域")
    @GetMapping(value = "/equipmentmanagement/getequipmentinstalllocationlist")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<DictResp>> getInstallAreas(){
        return equipmentService.getInstallAreas();
    }

    @ApiOperation(value = "获取设备管理员")
    @GetMapping(value = "/basicssysuser/getlistasync")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<DictResp>> getEquipmentAdmin(){
        return equipmentService.getEquipmentAdmin();
    }


    @ApiOperation(value = "获取设备")
    @GetMapping(value = "/basicssysuser/getEquipment")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<DictResp>> getEquipment(){
        return equipmentService.getEquipment();
    }


    @ApiOperation(value = "设备台账详情")
    @PostMapping(value = "/equipmentmanagement/getequipmentmanagementdetail")
    @ResponseBody
    @JWTAuth
    public CommonResult<EquipmentDetailsResp> getEquipmentDetails(@RequestBody @Valid SelectDetailReq req){
        return equipmentService.getEquipmentDetails(req.getId());
    }

    @ApiOperation(value = "进入设备绑定设计资料（头部路径）")
    @PostMapping(value = "/designinformation/getdesigninformationdetailbyid")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<FolderPreviewResp>> getFilePath(@RequestBody @Valid SelectDetailReq req){
        return equipmentService.getFilePath(req.getId());
    }


    @ApiOperation(value = "获取设备对象")
    @PostMapping(value = "/basicssysuser/getEquipmentObject")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<EquipmentObjectResp>> getEquipmentObject(@RequestBody EquipmentObjectReq req){
        return  CommonResult.success(equipmentService.getEquipmentObject(req));
    }


    @ApiOperation(value = "获取部门")
    @GetMapping(value = "/basicssysuser/getDept")
    @ResponseBody
    @JWTAuth
    public CommonResult<List<DictResp>> getDept(){
        return equipmentService.getDept();
    }



    @ApiOperation(value = "首页设备基本信息")
    @GetMapping(value = "/equipmentmanagement/getindexequipmentstatisticsinfo/{equipmentId}")
    @ResponseBody
    @JWTAuth
    public CommonResult<EquipmentStatisticsResp> getEquipmentStatistics(@PathVariable String equipmentId){
        return  CommonResult.success(equipmentService.getEquipmentStatistics(equipmentId));
    }



}
